13. Find the Fish Eaters

Find the Fish Eaters

Question:

Start Quiz:

#
# Find the names of the individual animals that eat fish.
#
# The animals table has columns (name, species, birthdate) for each individual.
# The diet table has columns (species, food) for each food that a species eats.
#

QUERY = '''
select ...
'''

User's Answer:

(Note: The answer done by the user is not guaranteed to be correct)

#
# Find the names of the individual animals that eat fish.
#
# The animals table has columns (name, species, birthdate) for each individual.
# The diet table has columns (species, food) for each food that a species eats.
#

QUERY = '''
select animals.name from animals, diet where animals.species=diet.species, diet.food = 'fish'
'''

Solution:

INSTRUCTOR NOTE:

To join two tables, first choose the join condition, or the rule you want the database to use to match rows from one table up with rows of the other table. Then write a join in terms of the columns in each table.

For instance, if you want to join tables T and S by matching rows where T.color is the same as S.paint, you'd write a select statement using T join S on T.color = S.paint.